import 'package:flutter/material.dart';
import 'package:toast/toast.dart';

class DrawerDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'DrawerDemo',
      home: MyDrawerDemoApp(),
    );
  }
}

enum ConferenceItem { AddMember, LockConference, ModifyLayout, TurnoffAll }

class MyDrawerDemoApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('DrawerDemo'),
        actions: <Widget>[
          FlatButton(
            onPressed: () {},
            child: PopupMenuButton<ConferenceItem>(
              onSelected: (result) {
                Toast.show(result.toString(), context);
                switch (result) {
                  case ConferenceItem.AddMember:
                    break;
                  case ConferenceItem.LockConference:
                    break;
                  case ConferenceItem.ModifyLayout:
                    break;
                  case ConferenceItem.TurnoffAll:
                    break;
                }
              },
              itemBuilder: (context) => <PopupMenuEntry<ConferenceItem>>[
                    PopupMenuItem<ConferenceItem>(
                        value: ConferenceItem.AddMember,
                        child: Text('AddMember')),
                    PopupMenuItem<ConferenceItem>(
                        value: ConferenceItem.LockConference,
                        child: Text('LockConference')),
                    PopupMenuItem<ConferenceItem>(
                        value: ConferenceItem.ModifyLayout,
                        child: Text('ModifyLayout')),
                    PopupMenuItem<ConferenceItem>(
                        value: ConferenceItem.TurnoffAll,
                        child: Text('TurnoffAll'))
                  ],
            ),
          )
        ],
      ),
      body: Center(
          child: AlertDialog(
        title: Text('AlertDialog'),
        content: SingleChildScrollView(
          child: ListBody(
            children: <Widget>[Text('确认要删除吗？')],
          ),
        ),
        actions: <Widget>[
          FlatButton(
              onPressed: () {
                Toast.show('确定', context, gravity: Toast.TOP);
              },
              child: Text('确定')),
          FlatButton(
              onPressed: () {
                Scaffold.of(context)
                    .showSnackBar(SnackBar(content: Text('取消')));
              },
              child: Text('取消'))
        ],
      )),
      drawer: Drawer(
        child: ListView(
          children: <Widget>[
            UserAccountsDrawerHeader(
              accountName: Text('Curry'),
              accountEmail: Text('curry@gmail.com'),
              currentAccountPicture: CircleAvatar(
                backgroundImage: AssetImage('images/logo_launch.png'),
              ),
            ),
            ListTile(
              leading: CircleAvatar(child: Icon(Icons.color_lens)),
              title: Text('个性装扮'),
            ),
            ListTile(
              leading: CircleAvatar(child: Icon(Icons.color_lens)),
              title: Text('个性装扮'),
            ),
            ListTile(
              leading: CircleAvatar(child: Icon(Icons.color_lens)),
              title: Text('个性装扮'),
            ),
            ListTile(
              leading: CircleAvatar(child: Icon(Icons.color_lens)),
              title: Text('个性装扮'),
            )
          ],
        ),
      ),
      floatingActionButton: Builder(builder: (context) {
        return FloatingActionButton(
            child: Icon(Icons.add),
            onPressed: () {
              Scaffold.of(context)
                  .showSnackBar(SnackBar(content: Text('snackbar')));
            });
      }),
      floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
    );
  }
}
